﻿
@{
    ViewData["Title"] = "GroupList";
}
@using ViewModel.admin
@model PagerModel

<div class="weadmin-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">管理员管理</a>
        <a>
            <cite>角色管理</cite>
        </a>
    </span>
    <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>
</div>
<div class="weadmin-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 we-search" action="@Url.Action("GroupList")">
            @*<div class="layui-inline">
                    <input class="layui-input" placeholder="开始日" name="start" id="start">
                </div>
                <div class="layui-inline">
                    <input class="layui-input" placeholder="截止日" name="end" id="end">
                </div>*@
            <input type="hidden" name="Page" id="PageIndex" />
            <input type="hidden" name="PageSize" id="PageSize" />
            <div class="layui-inline">
                <input type="text" name="Name" placeholder="请输入用户名" value="@ViewBag.Name" autocomplete="off" class="layui-input">
            </div>
            <button class="layui-btn" lay-submit="" id="btnSreach" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <div class="weadmin-block">
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="WeAdminShow('添加用户','@Url.Action("GroupEdit")')"><i class="layui-icon"></i>添加</button>
        <span class="fr" style="line-height:40px">共有数据：@Model.Total 条</span>
    </div>
    <table class="layui-table">
        <thead>
            <tr>
                <th>
                    <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
                </th>
                <th>ID</th>
                <th>角色名</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.Data as List<sys_admin_groupVm>)
            {
                <tr>
                    <td>
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='@item.id'><i class="layui-icon">&#xe605;</i></div>
                    </td>
                    <td>@item.id</td>
                    <td>@item.gname</td>
                    <td class="td-manage">
                        <a title="编辑" onclick="WeAdminShow('编辑','@Url.Action("GroupEdit")?id=@item.id')" href="javascript:;">
                            <i class="layui-icon">&#xe642;</i>
                        </a>
                        <a title="删除" onclick="member_del(this,'@item.id')" href="javascript:;">
                            <i class="layui-icon">&#xe640;</i>
                        </a>
                    </td>
                </tr>
            }

        </tbody>
    </table>
    <div id="pager"></div>

</div>


@section Scripts{
    <script type="text/javascript">

        //layui-form-checked
        layui.extend({
	        admin: '{/}../../static/js/admin'
        });

        layui.use(['laypage','admin'], function () {
            var laypage = layui.laypage;

            //执行一个laypage实例
            laypage.render({
                elem: 'pager' //注意，这里的 test1 是 ID，不用加 # 号
                , count: "@Model.Total" //数据总数，从服务端得到
                , pages: "@Model.GetTotalPage()"
                , curr: "@Model.Page"
                , limit:"@Model.PageSize"
                , jump: function (obj, first) {
                    //obj包含了当前分页的所有参数，比如：
                    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                    console.log(obj.limit); //得到每页显示的条数
                    //首次不执行
                    if (!first) {
                        //do something
                        $("#PageIndex").val(obj.curr);
                        $("#PageSize").val(obj.limit);
                        $("#btnSreach").click();
                    }
                }
            });
        });
        window.delAll = function (argument) {
            var data = tableCheck.getData();
            layer.confirm('确认要删除吗？' + data, function (index) {
                //捉到所有被选中的，发异步进行删除
                if (data!=''&&data!=null) {
                        $.post("@Url.Action("GroupDelete")", {ids:String(data)}, function (data) {
                        if (data=="success") {
                            layer.msg('已删除', {
                                icon: 1
                            });
                            $(".layui-form-checked").not('.header').parents('tr').remove();
                        } else {
                            layer.msg('删除失败，原因：'+data, {
                                icon: 2
                            });
                        }
                    })
                } else {
                    layer.msg('请选择要删除的数据', {
                        icon: 2
                    });
                }
            });
        }

        /*用户-删除*/
        window.member_del = function (obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                //发异步删除数据

                $.post("@Url.Action("GroupDelete")", { ids: id}, function (data) {
                    if (data=="success") {
                        layer.msg('已删除', {
                            icon: 1
                        });
                        $(obj).parents("tr").remove();
                    } else {
                        layer.msg('删除失败，原因：'+data, {
                            icon: 2
                        });
                    }
                })
            });
        }



    </script>
}